import time
import pyautogui
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from hyrobot.common import CHECK_POINT, STEP

from lib.webui import  *

class c73582:
    name = '验证全屏功能-73582' # 测试用例名字

# 初始化方法
    def setup(self):
        STEP(1, '登陆网站')
        wd = open_browser()
        mgr_login(wd)

    #清除方法
    def teardown(self):
        wd = get_global_webdriver()
        wd.quit()

    # 测试用例步骤
    def teststeps(self):
        # 获取webdriver对象 对应 已经登录好的浏览器
        driver = get_global_webdriver()
        # driver = webdriver.Firefox()


        # 比较id为app的元素的大小
        original_size = driver.find_element_by_id("app").size
        full_screen_button = driver.find_element_by_id("screenfull")
        STEP(1, "点击全屏按钮")
        time.sleep(1)
        full_screen_button.click()
        time.sleep(1)
        full_screen_size = driver.find_element_by_id("app").size

        STEP(2, "比较原页面大小与全屏后页面大小")
        CHECK_POINT("界面全屏后页面大小大于原页面大小",
                    original_size['height'] < full_screen_size['height'])

        STEP(3,"点击键盘esc退出")
        pyautogui.press('esc')
        time.sleep(1)
        return_size = driver.find_element_by_id("app").size
        CHECK_POINT("退出界面全屏后页面大小等于原页面大小",
                    return_size['height'] == original_size['height'])
        time.sleep(1)
        full_screen_button.click()
        time.sleep(1)
        full_screen_size1 = driver.find_element_by_id("app").size

        STEP(4, "第二次比较原页面大小与全屏后页面大小")
        CHECK_POINT("界面全屏后页面大小大于原页面大小",
                    original_size['height'] < full_screen_size1['height'])

        STEP(3, "点击id左侧按钮退出")
        time.sleep(1)
        full_screen_button.click()
        return_size1 = driver.find_element_by_id("app").size
        CHECK_POINT("第2次退出界面全屏后页面大小等于原页面大小",
                    return_size1['height'] == original_size['height'])
